<template>
  <el-container>
    <el-main>
      <StElDynamicForm :helper-form="helperForm" :submit-props="{method: 'get',loading: searchLoading,onSubmit:(form,data)=>{queryParams = $stObjectTools.clone(data)}}"
                       :options="MessageFormOptions" :origin-prop="{inline: true,labelWidth: '100px'}">
        <template #buttons>
          <el-button v-bind="$stElStyleTools.aiButtonStyle('添加')"
                     @click="$router.push(MessageUrl.router.add)" size="mini">添加
          </el-button>
        </template>
      </StElDynamicForm>
      <StElTable ref="steltable" :options="MessageTableOptions" @loading="(val)=>{searchLoading = val}" :datas="MessageUrl.searchList" :query-params="queryParams">
        <template #append>
          <el-table-column
              label="操作"
              width="200">
            <template #default="{row,column,$index}">
              <StElButtonGroup :group-param="{row,column,$index}" :operationMoreButtonOptions="{stype: 'link'}" :operations="tableOperations">
              </StElButtonGroup>
            </template>
          </el-table-column>

        </template>
      </StElTable>
    </el-main>
  </el-container>
</template>

<script>
import MessageMixin from '../MessageMixin.js'
import MessageUserStateUrl from '../MessageUserStateUrl.js'
export default {
  name: "MessageSearchList",
  mixins: [MessageMixin],
  props: {
  },
  computed: {
  },
  data() {
    return {
      queryParams: {},
      searchLoading:  false,

      helperForm: {
      },

      tableOperations: [{
        label: '删除',
        stype: 'link',
        loading: false,
        disabled: ({groupParam})=>{
          return groupParam.row.sendStatusDictCode == 'sending' || groupParam.row.sendStatusDictCode == 'sent'
        },
        requestSuccess: ({groupParam}) => {
          // 删除当前行，不重新请求
          this.$refs.steltable.getTableData().splice(groupParam.$index, 1)
        },
        action: ({groupParam}) => {
          return {
            method: 'delete',
            url: this.$stStringTools.replaceb(this.MessageUrl.delete, {id: groupParam.row.id}),
            confirmText: `确定删除 ${groupParam.row.name}吗`
          }
        }
      },
        {
          label: '修改',
          stype: 'link',
          disabled: ({groupParam})=>{
            return groupParam.row.sendStatusDictCode == 'sending' || groupParam.row.sendStatusDictCode == 'sent'
          },
          action: ({groupParam}) => {
            this.$router.push({path: this.MessageUrl.router.update, query: {id: groupParam.row.id}})
          }
        },
        {
          label: '用户列表',
          stype: 'link',
          action: ({groupParam}) => {
            this.$router.push({path: MessageUserStateUrl.router.searchList, query: {messageId: groupParam.row.id}})
          }
        },
        {
          label: '发送',
          stype: 'link',
          disabled: ({groupParam})=>{
            return groupParam.row.sendStatusDictCode == 'sending' || groupParam.row.sendStatusDictCode == 'sent'
          },
          action: ({groupParam}) => {
            this.$router.push({path: this.MessageUrl.router.update, query: {id: groupParam.row.id}})
          }
        },
      ]
    }
  },
  methods: {
  }
}
</script>

<style scoped>

</style>